package com.hjm.ui.common;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.google.android.material.divider.MaterialDivider;
import com.hjm.ui.R;

public class PartitionColumn extends LinearLayout {
    MaterialDivider dividerLeft, dividerRight;
    ImageView dividerImageView;
    TextView dividerTextView;
    public PartitionColumn(Context context) {
        super(context);
        init();
    }

    public PartitionColumn(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PartitionColumn);
        boolean dividerImgShow = a.getBoolean(R.styleable.PartitionColumn_dividerImgShow, false);
        Drawable drawable = a.getDrawable(R.styleable.PartitionColumn_dividerImg);
        String string = a.getString(R.styleable.PartitionColumn_dividerText);
        if(dividerImgShow){
            dividerImageView.setVisibility(View.VISIBLE);
        }
        if(drawable!=null){
            dividerImageView.setImageDrawable(drawable);
        }
        if(string!=null){
            dividerTextView.setText(string);
        }
    }

    public PartitionColumn(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private void init() {
        // 在这里添加你的布局和逻辑
        LayoutInflater.from(getContext()).inflate(R.layout.layout_partition_column, this, true);
        dividerLeft = findViewById(R.id.divide_left);
        dividerRight = findViewById(R.id.divide_right);
        dividerImageView = findViewById(R.id.image_view_divide);
        dividerTextView = findViewById(R.id.text_view_divide);
    }
}
